﻿using System;
using XingLucifer.Devices;
using XingLucifer.IBase.Enums;
using XingLucifer.IBase;
using XingLucifer.IBase.Models.PLCInteraktion; 
using System.Diagnostics;

namespace TestConsole
{
    internal class Program
    {
        static void Main(string[] args)
        {
            
            Console.WriteLine("开始通信串口服务器");
            ICommunication com = null;
            var tokenSource = new System.Threading.CancellationTokenSource();
            com = new TCPCom(199, "192.168.10.100", 44818, DeviceTypes.CIP_Omron, 1, TaskTypes.扫描信号, "", tokenSource, EndianTypes.CIP_Omron);
            OmronCIP devices = (OmronCIP)EquipmentFactory.NewSocketDevice(199, "192.168.10.100", 44818, XingLucifer.IBase.Enums.DeviceTypes.CIP_Omron, 1, XingLucifer.IBase.Enums.TaskTypes.扫描信号, "测试", tokenSource, com);
            //if (devices.Open())
            //{
            //    Console.WriteLine("打开成功");
            //    //BatteryArrayModel batteryArrayModel = new BatteryArrayModel(1);
            //    Stopwatch stopwatch = new Stopwatch();
            //    stopwatch.Restart();
            //    BatteryArrayModel injectionDataArrayModel = new BatteryArrayModel(4);
            //    for (int i = 0; i < 1000; i++)
            //    {
            //        devices.ReadClass("PC_Miscellaneous.ShortCicute", injectionDataArrayModel);
            //       // Console.WriteLine(System.Text.Json.JsonSerializer.Serialize(injectionDataArrayModel));
            //    }
            //    stopwatch.Stop();
            //    Console.WriteLine($"连续读取1000次 耗时==>>{stopwatch.ElapsedMilliseconds} ms");
            //    //Console.WriteLine("====================写入===================");
            //    ////devices.WriteSingle("1256069580", "PC_ScanCode.BeforeScan[1].Code");
            //    //devices.WriteSingle((long)12345678, "PC_ScanCode.BeforeScan[1].face.ID");
            //    //devices.WriteSingle((short)2, "PC_CMD.BeforeScanCMD[0]");

            //    //BatteryModel batteryModel = new BatteryModel() { ID = 1646464, Data_PLC = 63.24F, Data_PC = 23.36F, Results_PC = 666, Results_PLC = 45 };
            //    //devices.WriteClass(batteryModel, label:"PC_ScanCode.BeforeScan[0].face", crc:35167);
            //}
            //else
            //{
            //    Console.WriteLine("打开失败");
            //}
            if (devices.Open())
            {
                Console.WriteLine("打开成功!!!");
                devices.ReadClass<BatteryModel>("PC_ScanCode.BeforeScan[0].face");
            }
            else
            {
                Console.WriteLine("打开通信失败！！！");
            }

            devices.Close();
            Console.WriteLine("关闭通信");
            Console.ReadLine();
        }
    }
}
